package openadmin.model.object;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

import openadmin.dao.Base;
import openadmin.model.person.Person;

@Entity
@Table(name = "share", schema = "object", uniqueConstraints = @UniqueConstraint(columnNames="description"))
public class Share implements Base, java.io.Serializable{

	/** attribute that contains the identifier*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)	
	private Long id;
	
	/** attribute that contains the description, unique value*/
	@Length(max = 60)
	@NotNull
	private String description;
	
	private int part;
	
	/** attribute that contains TI=titular, RE=representant*/
	@Length(max = 2)
	@NotNull
	private String capacity;
	
	/** attribute that contains the relationship with Tax*/
	@ManyToOne
	@JoinColumn(name = "tax", nullable= false)
	private Tax tax;
	
	@Length(max = 2)
	private String state;
	
	/** attribute that contains the relationship with Person*/
	@ManyToOne
	@JoinColumn(name = "person", nullable= false)
	private Person person;
	
	/** attribute that contains the relationship with Person that representation*/
	@ManyToOne
	@JoinColumn(name = "representation", nullable= false)
	private Person representation;	
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date begindate;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date enddate;
	
	/** Transient attribute that means that the system should make a log on any JPA operation of this class*/
	@Transient
	boolean debuglog = true;
	
	/** Transient attribute that means that the system should make a historic on any JPA operation of this class*/
	@Transient
	boolean historiclog = false;
	
	public Share() {
		super();
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = person.getNif()+tax.getNio()+begindate;
	}
	
	public int getPart() {
		return part;
	}

	public void setPart(int part) {
		this.part = part;
	}

	public Tax getTax() {
		return tax;
	}

	public void setTax(Tax tax) {
		this.tax = tax;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}
	
	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public Date getBegindate() {
		return begindate;
	}

	public void setBegindate(Date begindate) {
		this.begindate = begindate;
	}

	public Date getDateend() {
		return enddate;
	}

	public void setDateend(Date dateend) {
		enddate = dateend;
	}
	
	public boolean getDebugLog() {
		return debuglog;
	}

	public void setDebuglog(boolean debuglog) {
		this.debuglog = debuglog;
	}
	
	public boolean getHistoricLog() {
		return historiclog;
	}

	public void setHistoricLog(boolean historiclog) {
		this.historiclog = historiclog;
	}
	
	@Override
	public String toString(){
		 
		return description;
	}

	public String getCapacity() {
		return capacity;
	}

	public void setCapacity(String capacity) {
		this.capacity = capacity;
	}

	public Date getEnddate() {
		return enddate;
	}

	public void setEnddate(Date enddate) {
		this.enddate = enddate;
	}

	public Person getRepresentation() {
		return representation;
	}

	public void setRepresentation(Person representation) {
		this.representation = representation;
	}
	
}
